﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


public class MathUtils
{
    const float kEpsilon = 0.00001F;
    public static float[] Normalize(float x, float y, float z)
    {
        float mag = Magnitude(x, y, z);
        if (mag > kEpsilon)
            return new float[] { x / mag, y / mag, z / mag };
        else
            return null;
    }

    public static float Magnitude(float x, float y, float z)
    {
        return (float)Math.Sqrt(x * x + y * y + z * z);
    }

    /// <summary>
    /// 唯一ID
    /// </summary>
    public static int UniqueID
    {
        get
        {
            return BitConverter.ToInt32(Encoding.UTF8.GetBytes(System.Guid.NewGuid().ToString()), 0);
        }
    }

    /// <summary>
    /// 唯一ID
    /// </summary>
    public static long UniqueLID
    {
        get
        {
            return BitConverter.ToInt64(Encoding.UTF8.GetBytes(System.Guid.NewGuid().ToString()), 0);
        }
    }
}

